HybridMail Technical - Address Heuristics
Updated: 15-10-2025 13:23

Address Heuristics

Address Heuristics is a method of detecting an address based on the look and feel of the text rather than relying on a valid postcode or town name. It is a better method for detecting text that is (to the human eye) clearly intended to be an address even though it is not strictly valid, and conversely, detecting text that is clearly not intended to be an address, even though it may contain a valid town name or even a postcode.

Enabling Address Heuristics

XML Attachment Schema

<mkzAttachments>
	<mkzAttachment type="standard">
		<onPreview>
			<adjust property="useAddressHeuristics">true</adjust>

			<!-- The following section is OPTIONAL.  It is shown here simply to indicate the tests that are performed 
			  and the default score for each test.  If you need different values, you need only specify those values 
			  that you wish to change.  To disable a particular test, set the score for that test to zero. --> 
			<addressHeuristics  requiredScore="6.2 or 3.0" [scan="X,Y,W,H"] >
				<numLines min="3" max="8">1.0</numLines>
				<leftJustified>1.0</leftJustified>
				<emptyLeft mm="15">1.5</emptyLeft>
				<emptyAbove mm="6">1.3</emptyAbove>
				<emptyBelow mm="6">1.3</emptyBelow>
				<emptyRight mm="15">1.5</emptyRight>
				<postCode>2.8</postCode>
				<townName>2.2</townName>
				<countryName>2.5</countryName>
				<keyword is="IG:">-99.0</keyword>
				<keyword is="road">0.6</keyword>
				<keyword is="street">0.7</keyword>
				<keyword is="lane">0.6</keyword>
				<keyword is="avenue">0.7</keyword>
				<keyword is="drive">0.4</keyword>
				<keyword is="park">0.4</keyword>
			</addressHeuristics>
		</onPreview>
	</mkzAttachment>
</mkzAttachments>

Address Heuristics are currently supported by the QuickPost page.

To use address heuristics, the only XML element required is the following in the onPreview section

<adjust property="useAddressHeuristics">true</adjust>

This enables address detection using the default values listed in the addressHeuristics section.

Address detection is performed by using the same techniques as a human eye. I.e. recognising a small block of text, a few lines only, surrounded by blank space, with keywords such as 'street' and/or what looks like a postcode. A score is assigned to each feature and, if the total score exceeds the requirement, the text is declared to be an address.

All the following elements are OPTIONAL. Only specify them if you wish to alter the parameters or the score.
N.B. Setting the score to 0 disables the element and the test is not performed.
<addressHeuristics requiredScore="9.0" scan="X,Y,W,H">

This element is only used if you want to alter any of the contained values:

The requiredScore attribute determines the score required to declare that an address has been detected. E.g.

requiredScore="9.0"  The sum of the accumulated visual and content scores must reach this value.

requiredScore="6.2 or 3.0"  The accumulated score needed must either reach 6.2 for visual tests or 3.0 for content tests. This is the default.

requiredScore="6.2 and 3.0"  The accumulated score needed must reach 6.2 for visual tests and 3.0 for content tests.

scan="X,Y,W,H"  The area to scan for text. This is only used by the TextXml utility and is ignored by the QuickPost page. The address area defined by the envelope and shown in the web page is used instead.

<numLines  min="3" max="8">1.0</numLines>

Score the specified value if the number of lines in the text block is between  min and  max .

<leftJustified>1.0</leftJustified>

Score the specified value if the text block is left-justified.

<emptyLeft min="15" >1.5</emptyLeft>

Score the specified value if there is at least  mm mm of blank space to the left of the text block.

<emptyAbove min="6" >1.2</emptyAbove>

Score the specified value if there is at least  mm mm of blank space above the text block .

<emptyBelow min="6" >1.2</emptyBelow>

Score the specified value if there is at least  mm mm of blank space below the text block.

<emptyRight min="15" >1.5</emptyRight>

Score the specified value if there is at least  mm mm of blank space to the right of the text block.

<postCode>2.8</postCode>

Score the specified value if one (and only one) of the last 3 lines of the text block ends with a correctly formatted UK postcode. The postcode is not checked for validity, only for the correct format.

<townName>2.2</townName>

Score the specified value if any of the last 3 lines of the text block starts with the name of a large town or city. The HybridMail database contains a list of the 1000 largest population centres in the UK.

<countryName>2.5</countryName>

Score the specified value if one (and only one) of the last 3 lines of the text block is the name of a country. The country name must occupy the whole line. The HybridMail database contains a list of all recognised countries in the world.

<keyword is="word-or-phrase" >score-value</keyword>

Score the specified value if  word-or-phrase appears in the text block. The score is only added once, even if the text block contains multiple matches.

The test matches whole words only.

E.g. <keyword is="right" >0.7</keyword>  The score will be added if the text block contains "right", but not if it contains "brightness" or "rightful".

Note, you can use this to forcibly ignore an address by setting the score to a large negative number.

E.g. <keyword is="IgnoreMe" >-99.9</keyword>